﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.ServiceModel;
using YamahaTuanTruc.StatisticService;
using BusinessObject;

namespace YamahaTuanTruc
{
    public partial class FrmBusinessStatistics : Form
    {
        public FrmBusinessStatistics()
        {
            InitializeComponent();
        }

        private void kryptonDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void qcibMonth_InputBox_SelectedItemChanged(object sender, EventArgs e)
        {
            
        }

        private void qcibMonth_ItemSelected(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
        {
            //MessageBox.Show(qcibMonth.Items.ToString());
        }

        private void qcibMonth_InputBox_SelectedIndexChanged(object sender, EventArgs e)
        {
           
            //MessageBox.Show(qcibMonth.InputBox.SelectedIndex.ToString());
            if (qcibYear.InputBox.SelectedIndex != -1)
            {
                string month = (qcibMonth.InputBox.SelectedIndex + 1).ToString();
                string year = qcibYear.InputBox.SelectedText.ToString();
                using (var service = new StatisticServiceClient())
                {
                     SuaChua[] lst = null;
                    try
                    {
                       lst = service.GetListBusByMonth(month, year);
                       if (lst != null && lst.Length > 0)
                       {
                           for (int i = 0; i < lst.Length; i++)
                           {
                               dgvBussiness.Rows.Add();
                               string thanhtien = (lst[i].DonGia * lst[i].SoLuong + lst[i].ChiPhiPhatSinh + lst[i].TienBaoDuong).ToString();
                               dgvBussiness.Rows[i].Cells[0].Value = lst[i].Xe.NgayNhanXe.ToString();
                               dgvBussiness.Rows[i].Cells[1].Value = lst[i].Xe.Ten.ToString();
                               dgvBussiness.Rows[i].Cells[2].Value = lst[i].ChiTietCongViec.ToString();
                               dgvBussiness.Rows[i].Cells[3].Value = lst[i].DonGia.ToString();
                               dgvBussiness.Rows[i].Cells[4].Value = lst[i].SoLuong.ToString();
                               dgvBussiness.Rows[i].Cells[5].Value = lst[i].ChiPhiPhatSinh.ToString();
                               dgvBussiness.Rows[i].Cells[6].Value = lst[i].TienBaoDuong.ToString();
                               dgvBussiness.Rows[i].Cells[7].Value = thanhtien;
                               dgvBussiness.Rows[i].Cells[8].Value = lst[i].GhiChu;
                           }
                       }
                       else
                       {
                           MessageBox.Show("Không có dữ liệu cho tháng này.");
                       }
                    }
                    catch (FaultException exception)
                    {
                        MessageBox.Show(exception.Reason.ToString());
                        MessageBox.Show(exception.StackTrace);
                        
                    }
                    
                }
            }
            else
            {
                
            }
        }

        private void FrmBusinessStatistics_Load(object sender, EventArgs e)
        {
            this.qcibMonth.InputBox.Items.AddRange(new object[] {
            "Tháng 1",
            "Tháng 2",
            "Tháng 3",
            "Tháng 4",
            "Tháng 5",
            "Tháng 6",
            "Tháng 7",
            "Tháng 8",
            "Tháng 9",
            "Tháng 10",
            "Tháng 11",
            "Tháng 12"});

            for (int i = 2005; i <= DateTime.UtcNow.Year; i++)
            {
                this.qcibYear.InputBox.Items.Add(i);
            }
            
        }

        private void qcibYear_InputBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            qcibMonth_InputBox_SelectedIndexChanged(sender, e);
        }
        //private static List<SuaChua> GetListBus 
    }
}
